package com.atguigu.gmall.search.controller;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.search.entity.SearchParamVo;
import com.atguigu.gmall.search.entity.SearchResponseVo;
import com.atguigu.gmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class SearchController {

    @Autowired
    SearchService searchService;
    @GetMapping("search")
    public String search(SearchParamVo searchParamVo, Model model){
        SearchResponseVo searchResponseVo = searchService.search(searchParamVo);
        searchResponseVo.setPageSize(searchParamVo.getPageSize());
        searchResponseVo.setPageNum(searchParamVo.getPageNum());
       model.addAttribute("searchParam",searchParamVo);
        model.addAttribute("response",searchResponseVo);
        return "search";
    }
}
